home *** CD-ROM | disk | FTP | other *** search
/ PCNet 2006 April / PCnet 2006-06.4.iso / shareware / nmsetup.exe / WebServer / web / webcamera.php < prev   
Encoding:
PHP Script  |  2006-05-01  |  10.3 KB  |  303 lines

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // <!--Copyright (c) 2006 Pure Networks Inc.  All rights reserved.-->
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // Build: 3.0.6121.0 (Stable)
  7. // $Revision: #1 $
  8. //
  9.  
  10. $sNavLocation = "webcamera";
  11. $sNavPage = "webcamera";
  12. $sLocation = "Web Camera";
  13. require '_session_common.php';
  14.  
  15. if (!$bLoggedIn && $bWebCameraIsPrivate)
  16. {
  17.     ///////////////////////////////////////////////////
  18.     // Webcamera is private and user is not logged in, go away.
  19.     ///////////////////////////////////////////////////
  20.     log_activity("private folder request without session", "error", return_error_text(308, "", $arErrors));
  21.     gotoAbs('/login/308');
  22.     exit();
  23. }
  24.  
  25. $bUnknownCameraType     =   false;
  26. $bIncompatibleBrowser   =   false;
  27. $sCamIPLastTwoOctets    =   "";
  28. $iErrorCode             =   0;
  29. $sCameraGuid            =   $_GET['Guid'];
  30. if (isValidString($sCameraGuid)) { $sCameraGuid=str_replace("\\\\", "\\", $sCameraGuid);} else { $sCameraGuid = ""; }
  31. $bValidCameraPassedViaGet   =   false;
  32. $sCamIPAddress          =   "";
  33. $sCamFriendlyName       =   "";
  34. $sCamVendorName         =   "";
  35. $sCamModelDescription   =   "";
  36. $sCamModelName          =   "";
  37. $sCamModelNumber        =   "";
  38. $sCamIPLastTwoOctets    =   "";
  39. $fCameraUSB             =   false;
  40. $fCameraOnline          =   false;
  41. $objCamera              =   null;
  42.  
  43. ///////////////////////////////////////////////////
  44. // let's get the cameras
  45. ///////////////////////////////////////////////////
  46. try
  47. {
  48.     if ($bAutoDetectWebCams && $bAutoDetectUSBCams)
  49.     {
  50.         $nmUSBCameras = $nmNetworkLib->USBCameras;
  51.         if (count($nmUSBCameras) > 0)
  52.         {
  53.             foreach ($nmUSBCameras as $camera)
  54.             {
  55.                 $nmCameras[] = $camera;
  56.             }
  57.         }
  58.  
  59.         $nmWebCameras = $nmNetworkLib->WebCameras;
  60.         if (count($nmWebCameras) > 0)
  61.         {
  62.             foreach ($nmWebCameras as $camera)
  63.             {
  64.                 $nmCameras[] = $camera;
  65.             }
  66.         }
  67.     }
  68.     else if ($bAutoDetectWebCams)
  69.     {
  70.         $nmCameras = $nmNetworkLib->WebCameras;
  71.     }
  72.     else if ($bAutoDetectUSBCams)
  73.     {
  74.         $nmCameras = $nmNetworkLib->USBCameras;
  75.     }
  76. }
  77. catch(Exception $ex)
  78. {
  79.     $nmCameras = null;
  80.     log_activity("Attempting nmNetworkLib->WebCameras", "exception", $ex->getMessage() . " (" . $ex->getCode() . ")");
  81. }
  82. if (count($nmCameras) > 0)
  83. {
  84.     foreach ($nmCameras as $camera)
  85.     {
  86.         try
  87.         {
  88.             if ($camera->Guid == $sCameraGuid)
  89.             {
  90.                 $objCamera                  =   $camera;
  91.                 $fCameraUSB                 =   $camera->USB;
  92.                 if (!$fCameraUSB)
  93.                 {
  94.                     $rIPAddressSplit        =   explode(".",$camera->IPAddress);
  95.                     $sCamIPLastTwoOctets    =   $rIPAddressSplit[2] . "." . $rIPAddressSplit[3];
  96.                     $sCamIPAddress          =   $camera->IPAddress;
  97.                 }
  98.                 $sCamFriendlyName           =   $camera->FriendlyName;
  99.                 $sCamVendorName             =   $camera->VendorName;
  100.                 $sCamModelDescription       =   $camera->ModelDescription;
  101.                 $sCamModelName              =   $camera->ModelName;
  102.                 $sCamModelNumber            =   $camera->ModelNumber;
  103.                 $fCameraOnline              =   $camera->Online;
  104.                 $bValidCameraPassedViaGet   =   true;
  105.             }
  106.         }
  107.         catch(Exception $ex)
  108.         {
  109.             // in case any of above aren't implemented, etc...
  110.             log_activity("Trying to find which camera we are dealing with", "exception", $ex->getMessage() . " (" . $ex->getCode() . ")");
  111.         }
  112.     }
  113. }
  114.  
  115. // if bValidCameraPassedViaGet is still false, we have some manipulation of GET params going on (OR bad camera...)
  116. if (!$bValidCameraPassedViaGet)
  117. {
  118.     log_activity("Webcamera guid not found: " . $sCameraGuid, "failure", return_error_text(510, "", $arErrors));
  119.     gotoAbs('/error/510');
  120.     exit();
  121. }
  122.  
  123. if (!$fCameraOnline)
  124. {
  125.     $iErrorCode = 513;
  126. }
  127.  
  128. try
  129. {
  130.     $sLanIp         = "http://" . $nmRaManager->LanIP;
  131.     $sWanIp         = $nmRaManager->HomeUrl;
  132.  
  133.     // We have the DNS URL, let's get the home. version of it to use in the direct URLs...
  134.     $iStartUrl          = strpos($sWanIp, "://") + 3;
  135.     $sUrl               = substr($sWanIp, $iStartUrl);
  136.     $iEndSubDomain      = strpos($sUrl, ".");
  137.     $sSubDomain         = substr($sUrl, 0, $iEndSubDomain);
  138.     $sWanIp             = str_replace($sSubDomain, $sSubDomain . "." . $sWaHomeSubDomain, $sWanIp);
  139.  
  140.     // see if they are accessing the site as a private address and respond accordingly
  141.     $sServerIpPort  = $_SERVER['HTTP_HOST'];
  142.     $iServerPortPos = strpos($sServerIpPort, ":");
  143.     $sServerIP      = substr($sServerIpPort, 0, $iServerPortPos);
  144.     if (isIpAddressPrivate($sServerIP))
  145.     {
  146.         $sIpToUse = $sLanIp;
  147.     }
  148.     else
  149.     {
  150.         $sIpToUse = $sWanIp;
  151.     }
  152.  
  153.     $sIpToUse         .= ":8008"; // TODO: remote port
  154.  
  155.     // only partial octets to avoid open redirector
  156.     $sIpToUse         .= "/internal/redir/" . $sCamIPLastTwoOctets . "/";
  157. }
  158.  
  159. catch (exception $ex)
  160. {
  161.     log_activity("Attempting nmRaManager->HomeUrl", "exception", $ex->getMessage() . " (" . $ex->getCode() . ")");
  162.     $iErrorCode = 513;
  163. }
  164.  
  165. ///////////////////////////////////////////////////
  166. // start printing out the HTML to the browser
  167. ///////////////////////////////////////////////////
  168. require "_header.php";
  169. require "_cookie_util.php";
  170.  
  171. try
  172. {
  173.  $sDebug = $_GET['Debug'];
  174.  if ("true" == $sDebug)
  175.  {
  176.      echo ("<br>Vendor: " . $sCamVendorName);
  177.      echo ("<br>ModelName: " . $sCamModelName);
  178.      echo ("<br>ModelNumber: " . $sCamModelNumber);
  179.      echo ("<br>ModelDescription: " . $sCamModelDescription);
  180.      echo ("<br>IPAddress: " . $sCamIPAddress);
  181.      echo ("<br>Guid: " . $sCameraGuid);
  182.      echo ("<br>IsUSB: " . $fCameraUSB);
  183.      echo ("<br>IpToUse:" . $sIpToUse);
  184.  }
  185. }
  186. catch (exception $ex)
  187. {
  188.   log_activity("Enumerating camera debug details", "exception", $ex->getMessage() . " (" . $ex->getCode() . ")");
  189. }
  190.  
  191. ?>
  192.  
  193.  
  194.     <table cellspacing="0" cellpadding="0" border="0" width="100%">
  195.         <tr>
  196.             <td width="100%" valign="top">
  197.                 <?php require "_public_error_states.php"; ?>
  198.                 <!-- Start Folder view table -->
  199.                     <table cellspacing="0" cellpadding="0" border="0" class="ContentTable">
  200.                         <tr>
  201.                             <td class="ContentTableTL"><div> </div></td>
  202.                             <td class="ContentTableTM2"><div><strong><?php echo(HtmlSpecialChars($sCamFriendlyName)); if ($fCameraUSB) { echo (" USB Camera" ); } else { echo (" Web Camera"); } ?></strong></div></td>
  203.                             <td class="ContentTableTM3"> </td>
  204.                             <td class="ContentTableTR"><div> </div></td>
  205.                         </tr>
  206.                         <tr>
  207.                             <td class="ContentTableML"><div> </div></td>
  208.                             <td class="ContentTableMM" colspan="2">
  209.                                 <div class="ShareContents"  style="text-align:center;">
  210.                                 <br/>
  211.  
  212. <?php
  213.  
  214.     if ($iErrorCode == 0)
  215.     {
  216.         require "cameras/webcamerautils.php";
  217.         staticImageStyleWriteOut("640", "480");
  218.  
  219.         // Figure out what vendor's camera.php to include
  220.         if ($fCameraUSB)
  221.         {
  222.             require "cameras/USB.php";
  223.         }
  224.         else if (strpos(strtolower($sCamVendorName),"d-link") !== false)
  225.         {
  226.             require "cameras/D-Link.php";
  227.         }
  228.         else if (strpos(strtolower($sCamVendorName),"trendnet") !== false)
  229.         {
  230.             require "cameras/TRENDnet.php";
  231.         }
  232.         else if (strpos(strtolower($sCamVendorName),"cellvision") !== false)
  233.         {
  234.             require "cameras/TRENDnet.php"; // purposefully use trendnet for cellvision
  235.         }
  236.         else if (strpos(strtolower($sCamVendorName),"linksys") !== false)
  237.         {
  238.             require "cameras/Linksys.php";
  239.         }
  240.         else if (strpos(strtolower($sCamVendorName),"veo") !== false)
  241.         {
  242.             require "cameras/Veo.php";
  243.         }
  244.         else
  245.         {
  246.             $iErrorCode = 511;
  247.         }
  248.     }
  249.  
  250.     if ($iErrorCode != 0)
  251.     {
  252. ?>
  253.         <table cellpadding="0" cellspacing="0" border="0">
  254.             <tr><td class="SucceedTableTop"><div> </div></td></tr>
  255.             <tr>
  256.                 <td class="SucceedTableMid" style="text-align:left;">
  257.                         <div class="EmptyContianerImage">
  258.                             <div class="EmptyContianerText">
  259.                                 An error occurred
  260.                             </div>
  261.                             <div class="EmptyContianerExplain">
  262.                                 <?php echo return_error_text($iErrorCode, "", $arErrors);?>
  263.                             </div>
  264.                         </div>
  265.                 </td>
  266.             </tr>
  267.             <tr><td class="SucceedTableBot"><img src="/images/pixel.trans.gif" width="1" height="1" alt=""/></td></tr>
  268.         </table>
  269. <?php
  270.  
  271.     }
  272. ?>
  273.                                 </div> <!--ShareContents-->
  274.                             </td>
  275.                             <td class="ContentTableMR"> </td>
  276.                         </tr>
  277.                         <tr>
  278.                             <td class="ContentTableBL"> </td>
  279.                             <td class="ContentTableBM" colspan="2"> </td>
  280.                             <td class="ContentTableBR"> </td>
  281.                         </tr>
  282.                     </table> <!-- End Folder View Table -->
  283.                 </td>
  284.                 <td valign="top">
  285. <?php
  286. ///////////////////////////////////////////////////
  287. // Define the tasks for this page
  288. ///////////////////////////////////////////////////
  289. $iTaskCount = 0;
  290.  
  291. require "_network_map.php";
  292. require "_tasks_panel.php";
  293. ?>
  294.                 </td>
  295.             </tr>
  296.         </table>
  297. <?php
  298. ///////////////////////////////////////////////////
  299. // Finish printing out the HTML to the browser
  300. ///////////////////////////////////////////////////
  301. require "_footer.php";
  302.  ?>
  303.